import ply.lex as lex


reserved = {
'if' : 'IF',
'then' : 'THEN',
'else' : 'ELSE',
'while' : 'WHILE',
'int'   : 'INT',
'void'  : 'VOID',
'main'  : 'MAIN',
'float' : 'FLOAT',
'char'  : 'CHAR',
'scanf' : 'SCANF',
'default': 'DEFAULT'
}


tokens = [
    'NUMBER',
    # 'PLUS',
    # 'MINUS',
    # 'TIMES',
    # # 'DIVIDE',
    # 'LPAREN',
    # 'RPAREN',
    'COMMENT',
    'EQ',
    'MORE',
    'LESS',
    'EMORE',
    'ELESS',
    'UEQ',
    'ID',
    'NOTZERO'
 ]+list(reserved.values())

literals = [ '{', '}','(',')','+','-','*','/','[',']','=',':',';']

t_EQ        =r'=='
t_MORE      =r'>'
t_LESS      =r'<'
t_EMORE    =r'>='
t_ELESS    =r'<='
t_UEQ      =r'!='
# t_PLUS      = r'\+'
# t_MINUS     = r'-'
# t_TIMES     = r'\*'
# t_DIVIDE    = r'/'
# t_LPAREN    = r'\('
# t_RPAREN    = r'\)'


def t_NUMBER(t):
    r'\d+'
    t.value = int(t.value,t.type)    
    return t

def t_NOTZERO(t):
    r'[1-9][0-9]*'
    t.value = int(t.value)


def t_newline(t):
     r'\n+'
     t.lexer.lineno += len(t.value)
 
 # A string containing ignored characters (spaces and tabs)
t_ignore  = ' \t'
 
 # Error handling rule
def t_error(t):
    print("Illegal character '%s'" % t.value[0])
    t.lexer.skip(1)

def t_ID(t):
     r'[a-zA-Z_][a-zA-Z_0-9]*'
     t.type = reserved.get(t.value,'ID')    # Check for reserved words
     t.value = (t.value,t.type)
     return t

def t_COMMENT(t):
     r'\#.*'
     pass
     # No return value. Token discarded


# Build the lexer
lexer = lex.lex()
# data = '''
# 3 + 4 * 10
# + -20 *2
# '''
data=input()
lexer.input(data)
while True:
    tok = lexer.token()
    if not tok: 
        break      # No more input
    print(tok)

#this one is use for loop to test the the token
# for tok in lexer:
#     print(tok)
